package constant.milk.toilet.setting;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import constant.milk.toilet.R;
import constant.milk.toilet.SuperActivity;

public class FontActivity extends SuperActivity
{
	public static final String FONT_DATA = "FONT_DATA";
	
	private TextView preView;
	private TextView titleTextView;
	
	private View smallView;
	private View normalView;
	private View bigView;
	
	private TextView smallMessageTextView;
	private TextView normalMessageTextView;
	private TextView bigMessageTextView;
	
	private TextView smallTextView;
	private TextView normalTextView;
	private TextView bigTextView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.setting_font_actvity);
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		preView = (TextView) findViewById(R.id.settingFontPreView);
		titleTextView = (TextView) findViewById(R.id.settingFontTitleTextView);
		
		smallView = findViewById(R.id.settingFontSmallView);
		normalView = findViewById(R.id.settingFontNormalView);
		bigView = findViewById(R.id.settingFontBigView);
		
		smallMessageTextView = (TextView) findViewById(R.id.settingFontSmallMessageTextView);
		normalMessageTextView = (TextView) findViewById(R.id.settingFontNormalMessageTextView);
		bigMessageTextView = (TextView) findViewById(R.id.settingFontBigMessageTextView);
		
		smallTextView = (TextView) findViewById(R.id.settingFontSmallTextView);
		normalTextView = (TextView) findViewById(R.id.settingFontNormalTextView);
		bigTextView = (TextView) findViewById(R.id.settingFontBigTextView);
	}

	@Override
	protected void setOnClick()
	{
		preView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				finish();
			}
		});
		
		smallView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(FONT_DATA, 0);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
		
		normalView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(FONT_DATA, 1);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
		
		bigView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				intent.putExtra(FONT_DATA, 2);
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		titleTextView.setTextColor(Color.WHITE);
		titleTextView.setTextSize(TEXT_SIZE + 2);
		
		SharedPreferences p = getSharedPreferences("pref", Activity.MODE_PRIVATE);
		int fontFlag = p.getInt(getString(R.string.prefFont), 1);
		
		setCheckFont(fontFlag);
		
		smallMessageTextView.setTextSize(12);
		normalMessageTextView.setTextSize(16);
		bigMessageTextView.setTextSize(20);
	}
	
	private void setCheckFont(int flag)
	{
		if (flag == 0)
		{
			smallTextView.setBackgroundResource(R.drawable.ic_font_checkbox);
			normalTextView.setBackgroundResource(0);
			bigTextView.setBackgroundResource(0);
		}
		else if (flag == 1)
		{
			smallTextView.setBackgroundResource(0);
			normalTextView.setBackgroundResource(R.drawable.ic_font_checkbox);
			bigTextView.setBackgroundResource(0);
		}
		else
		{
			smallTextView.setBackgroundResource(0);
			normalTextView.setBackgroundResource(0);
			bigTextView.setBackgroundResource(R.drawable.ic_font_checkbox);
		}
	}
}
